#define _CRT_SECURE_NO_WARNINGS   1

#include <iostream>
#include <algorithm>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int *a;
	a = new int[n];
	for (int i = 0; i < n; i++) 
	{
		cin >> a[i];
	}
	int result = a[0];
	for (int i = 1; i < n; i++) 
	{
		a[i] += max(a[i - 1], 0);
		result = max(result, a[i]);
	}
	cout << result << endl;
	return 0;
}
